//
//  RootTabBarController.m
//  糗事百科
//
//  Created by 奚超明 on 16/5/27.
//  Copyright © 2016年 奚超明. All rights reserved.
//

#import "RootTabBarController.h"
#import "ThingsViewController.h"
#import "FriendsTableViewController.h"
#import "FindTableViewController.h"
#import "NoteTableViewController.h"
#import "MeTableViewController.h"
#import "XCMNavgationViewController.h"

@interface RootTabBarController ()

@end

@implementation RootTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 糗事
    [self addTabBarChildViewControllerWithChildViewController:[[ThingsViewController alloc] init] title:@"糗事" image:[UIImage imageNamed:@"qsTB"] selectedImage:[UIImage imageNamed:@"qsTBClick"]];
    
    // 糗友圈
    [self addTabBarChildViewControllerWithChildViewController:[[FriendsTableViewController alloc] init] title:@"糗友圈" image:[UIImage imageNamed:@"friend"] selectedImage:[UIImage imageNamed:@"friendClick"]];
    
    // 发现
    [self addTabBarChildViewControllerWithChildViewController:[[FindTableViewController alloc] initWithStyle:UITableViewStyleGrouped] title:@"发现" image:[UIImage imageNamed:@"find"] selectedImage:[UIImage imageNamed:@"findClick"]];
    
    // 小纸条
    [self addTabBarChildViewControllerWithChildViewController:[[NoteTableViewController alloc] init] title:@"小纸条" image:[UIImage imageNamed:@"note"] selectedImage:[UIImage imageNamed:@"noteClick"]];
    
    // 我
    [self addTabBarChildViewControllerWithChildViewController:[[MeTableViewController alloc] initWithStyle:UITableViewStyleGrouped] title:@"我" image:[UIImage imageNamed:@"me"] selectedImage:[UIImage imageNamed:@"meClick"]];
    
}

#pragma mark - 添加tabBar的子控制器
- (void)addTabBarChildViewControllerWithChildViewController:(UIViewController *)childViewController title:(NSString *)title image:(UIImage *)image selectedImage:(UIImage *)selectedImage
{
    // 设置标题
    childViewController.tabBarItem.title = title;
    
    // 设置普通状态文字
    NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
    attributes[NSFontAttributeName] = [UIFont systemFontOfSize:11];
    attributes[NSForegroundColorAttributeName] = kRGBColor(136, 136, 136);
    [childViewController.tabBarItem setTitleTextAttributes:attributes forState:UIControlStateNormal];
    
    // 设置选中状态文字
    NSMutableDictionary *attributesSelect = [NSMutableDictionary dictionary];
    attributesSelect[NSFontAttributeName] = [UIFont systemFontOfSize:11];
    attributesSelect[NSForegroundColorAttributeName] = kOrangerColor;
    [childViewController.tabBarItem setTitleTextAttributes:attributesSelect forState:UIControlStateSelected];
    
    // 设置普通状态图片
    childViewController.tabBarItem.image = image;
    // 设置选中图片
    childViewController.tabBarItem.selectedImage = selectedImage;
    
    // 创建导航控制器
    XCMNavgationViewController *nav = [[XCMNavgationViewController alloc] initWithRootViewController:childViewController];
    
    // 将导航控制器加入tabBar子控制器数组中
    [self addChildViewController:nav];

}

@end
